<%@ page language = "java" import = "java.util.*" %>
<%@ page import = "edu.colorado.karl.manctrl.ManualControl" %>

<%@ include file = "header.jspf" %>

<link rel="Stylesheet" type="text/css" media="Screen" charset="utf-8" href="css/common.css"/>

<h1>Updating Setpoints...</h1>

<%

ManualControl mc = ManualControl.getManualControl();
boolean update = true;

//read in all data from the form
try
{
  int hotTank = Integer.parseInt(request.getParameter("hotTank"));
  int hotTankRange = Integer.parseInt(request.getParameter("hotTankRange"));
  int coldTank = Integer.parseInt(request.getParameter("coldTank"));
  int coldTankRange = Integer.parseInt(request.getParameter("coldTankRange"));

  if(hotTankRange < 1 || hotTankRange > 10 || coldTankRange < 1 || coldTankRange > 10)
  {
    update = false;
    %>

    <br>Error, range must be 1 - 10.
    <br><a link="manual_control.jsp">Return to manual control page</a>

    <%
  }

  if(hotTank < 80 || hotTank > 150)
  {
    update = false;
    %>

    <br>Error, hot tank temperature must be 80 - 150.
    <br><a link="manual_control.jsp">Return to manual control page</a>

    <%
  }

  if(coldTank < 0 || coldTank > 30)
  {
    update = false;
    %>

    <br>Error, cold tank temperature must be 0 - 30.
    <br><a link="manual_control.jsp">Return to manual control page</a>

    <%
  }

  //update the database entries
  if(update)
  {
    mc.updateTankSettings(hotTank,hotTankRange,coldTank,coldTankRange);
  }
}

//the user most likely entered a non-numerical or decimal value
catch(NumberFormatException e)
{
%>

  <br>Error, all inputs must be integers.
  <br><a link="manual_control.jsp">Return to manual control page</a>

<%
}

//check the tank mode setting
String tankMode = request.getParameter("tank_mode");

//set the new tank mode (if needed)
if(tankMode != null)
{
  if(tankMode.compareTo("tank_auto") == 0)
  {
    mc.setTankMode(true);
  }
  else
  {
    mc.setTankMode(false);
  }
}

%>

<meta http-equiv=REFRESH content=0;url=manual_control.jsp>

</body>
</html>